package ${packageName};

import java.util.List;
import java.util.Date;

<#list importPackage as imp>
import ${imp};
</#list>
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

/**   
 * Create by apisdk 
 */
@Service
public class ${className?cap_first} {
<#list services as service>
	@Autowired
	private ${service?cap_first} ${service?uncap_first};
</#list>

	/**
	* @description create model
	* @return
	*/
	public ${modelName?cap_first}Vo create${modelName?cap_first}(${modelName?cap_first}Vo ${modelName?uncap_first}Vo) throws Exception {
		${modelName?cap_first} ${modelName?uncap_first} = new ${modelName?cap_first}();
		BeanUtils.copyProperties(${modelName?uncap_first}Vo, ${modelName?uncap_first});
		${modelName?uncap_first} =  ${modelName?uncap_first}Repository.save(${modelName?uncap_first});
		BeanUtils.copyProperties(${modelName?uncap_first}, ${modelName?uncap_first}Vo);
		return ${modelName?uncap_first}Vo;
	}

	/**
	* @description get model through id
	* @return
	*/
	public List<${modelName?cap_first}Vo></Vo> get${modelName?cap_first}ByExample(${modelName?cap_first}Vo ${modelName?uncap_first}Vo){
		${modelName?cap_first} ${modelName?uncap_first} = new ${modelName?cap_first}();
		BeanUtils.copyProperties(${modelName?uncap_first}Vo, ${modelName?uncap_first});
	}

	/**
	* @description update model through id
	* @return
	*/
	public ${modelName?cap_first}Vo update${modelName?cap_first}ById(@PathVariable String id,@RequestBody ${modelName?cap_first}Vo ${modelName?uncap_first}Vo){
		//TODO to finish update code
		return ${modelName?uncap_first}Vo;
	}

	/**
	* @description delete model through id
	* @return
	*/
	public void delete${modelName?cap_first}ById(@PathVariable String id){
		${modelName?cap_first} ${modelName?uncap_first} =  ${modelName?uncap_first}Repository.findOne(id);
		if(${modelName?uncap_first}!=null){
			${modelName?uncap_first}Repository.delete(${modelName?uncap_first});
		}
		return;
	}

<#if methods??>
	<#list methods as po> 
	/**
	 * @description ${po.description!}
<#list po.parameters as sdkparam>
	 * @param ${sdkparam.name}
</#list>
	 * @return
	 */
	@RequestMapping(value= "${po.reqUrl}", method = RequestMethod.${po.verb})
	public <#if po.response.collection == true>List<${po.response.type}><#else>${po.response.type}</#if> ${po.methodName}(<#list po.parameters as sdkparam><#if sdkparam.source == 'Path'>@PathVariable <#elseif sdkparam.source == 'Body'>@RequestBody() <#else></#if><#if sdkparam.collection>List<${sdkparam.type}> ${sdkparam.name}<#else>${sdkparam.type} ${sdkparam.name}</#if><#if sdkparam_has_next>, </#if></#list>){
		<#if po.response.type == 'void'>
		${po.serviceName}.${po.methodName}(<#list po.parameters as sdkparam>${sdkparam.name}<#if sdkparam_has_next>, </#if></#list>);
		<#else>
		return ${po.serviceName}.${po.methodName}(<#list po.parameters as sdkparam>${sdkparam.name}<#if sdkparam_has_next>, </#if></#list>);
		</#if>
	}
	
	</#list>
	<#else>
</#if>
}
